package com.jinmdz.fmis.api.admin.controller;

import com.jinmdz.fmis.api.admin.model.equipment.EquipmentIdData;
import com.jinmdz.fmis.api.admin.model.equipment.EquipmentListData;
import com.jinmdz.fmis.api.admin.model.equipment.EquipmentLoadData;
import com.jinmdz.fmis.api.admin.model.equipment.EquipmentSaveData;
import com.jinmdz.fmis.api.admin.service.EquipmentExcelService;
import com.jinmdz.fmis.api.admin.service.EquipmentService;
import com.jinmdz.fmis.api.api.model.common.IdVersionData;
import com.jinmdz.fmis.api.base.BaseController;
import com.jinmdz.fmis.core.base.BasePageData;
import com.jinmdz.fmis.core.base.BaseResult;
import com.jinmdz.fmis.core.model.SearchLoadData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * 冷藏冷柜维护信息相关接口
 *
 * @author LiCongLu
 * @date 2020-03-11 11:29
 */
@Api(description = "冷藏冷柜维护信息相关接口")
@RestController()
@RequestMapping("/admin/equipment")
public class EquipmentController extends BaseController {

    @Resource
    private EquipmentService equipmentService;

    @Resource
    private EquipmentExcelService equipmentExcelService;

    /**
     * 分页加载冷藏冷柜信息
     *
     * @param data 分页条件
     * @return
     * @author LiCongLu
     * @date 2020-03-11 11:29
     */
    @ApiOperation(value = "分页加载冷藏冷柜信息", notes = "加载冷藏冷柜分类【cold_storage_equipment】表中所有有效冷藏冷柜信息")
    @PostMapping("/load-equipment-list")
    public BaseResult<SearchLoadData<EquipmentListData>> loadEquipmentList(@RequestBody BasePageData data) {
        return resultHandler(userItem -> equipmentService.loadEquipmentList(data));
    }

    /**
     * 加载冷藏冷柜信息，为可视化界面提供显示数据
     *
     * @param
     * @return
     * @author LiCongLu
     * @date 2020-03-11 11:29
     */
    @ApiOperation(value = "加载冷藏冷柜信息，为可视化界面提供显示数据", notes = "加载冷藏冷柜分类【cold_storage_equipment】表中所有有效冷藏冷柜信息")
    @PostMapping("/load-equipment-preview-list")
    public BaseResult<ArrayList<EquipmentListData>> loadEquipmentPreviewList() {
        return resultHandler(userItem -> equipmentService.loadEquipmentPreviewList());
    }

    /**
     * 加载冷藏冷柜信息
     *
     * @param data 主键
     * @return
     * @author LiCongLu
     * @date 2020-03-11 11:29
     */
    @ApiOperation(value = "根据【cold_storage_equipment】表中id加载冷藏冷柜信息", notes = "根据ID加载冷藏冷柜信息")
    @PostMapping("/load-equipment-with-id")
    public BaseResult<EquipmentLoadData> loadEquipmentWithId(@RequestBody EquipmentIdData data) {
        return resultHandler(data, userItem -> equipmentService.loadEquipmentWithId(data));
    }

    /**
     * 保存冷藏冷柜信息到cold_storage_equipment表中
     *
     * @param data 冷藏冷柜请求数据
     * @return
     * @author LiCongLu
     * @date 2020-03-11 11:29
     */
    @ApiOperation(value = "保存冷藏冷柜信息到【cold_storage_equipment】表中", notes = "保存冷藏冷柜信息到【cold_storage_equipment】表中")
    @PostMapping("/save-equipment")
    public BaseResult saveEquipment(@RequestBody EquipmentSaveData data) {
        return resultHandler(data, userItem -> equipmentService.saveEquipment(userItem, data));
    }

    /**
     * 根据Excel模板导入冷藏柜数据信息，用于冷柜数据初始化
     *
     * @param importExcelFile 冷藏冷柜导入表格
     * @return
     * @author LiCongLu
     * @date 2020-03-13 09:12
     */
    @ApiOperation(value = "根据Excel模板导入冷藏柜数据信息，用于冷柜数据初始化", notes = "从Excel中导入数据到表【cold_storage_equipment】，按冷柜类型进行导入，每次导入时数据库当前类型下原数据自动清空，用于冷柜数据初始化，功能仅提供给公司实施人员使用。")
    @PostMapping("/import-equipment-with-excel")
    public BaseResult importEquipmentWithExcel(@RequestParam(value = "importExcelFile") MultipartFile importExcelFile) {
        return resultHandler(userItem -> equipmentExcelService.importEquipmentWithExcel(userItem, importExcelFile));
    }

    /**
     * 从cold_storage_equipment表中删除指定id的冷藏冷柜信息记录
     *
     * @param data 主键和版本号
     * @return
     * @author LiCongLu
     * @date 2020-03-11 11:29
     */
    @ApiOperation(value = "从cold_storage_equipment表中删除指定id的冷藏冷柜信息记录", notes = "从cold_storage_equipment表中删除指定id的冷藏冷柜信息")
    @PostMapping("/delete-equipment-with-id")
    public BaseResult deleteEquipmentWithId(@RequestBody ArrayList<IdVersionData> data) {
        return resultHandler(data, userItem -> equipmentService.deleteEquipmentWithId(userItem, data));
    }
}
